{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import asyncio\n",
    "import os\n",
    "import asyncio\n",
    "\n",
    "from typing import Annotated\n",
    "from openai import AsyncOpenAI\n",
    "\n",
    "\n",
    "from semantic_kernel.kernel import Kernel\n",
    "from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion\n",
    "from semantic_kernel.agents import ChatCompletionAgent\n",
    "from semantic_kernel.contents import ChatHistory\n",
    "\n",
    "\n",
    "from semantic_kernel.agents.open_ai import OpenAIAssistantAgent\n",
    "from semantic_kernel.contents import AuthorRole, ChatMessageContent\n",
    "from semantic_kernel.functions import kernel_function\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "client = AsyncOpenAI(\n",
    "    api_key=os.environ[\"GITHUB_TOKEN\"], base_url=\"https://models.inference.ai.azure.com/\")\n",
    "\n",
    "kernel = Kernel()\n",
    "chat_completion_service = OpenAIChatCompletion(\n",
    "    ai_model_id=\"gpt-4o-mini\",\n",
    "    async_client=client,\n",
    "    service_id=\"agent\",\n",
    ")\n",
    "kernel.add_service(chat_completion_service)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "AGENT_NAME = \"TravelAgent\"\n",
    "AGENT_INSTRUCTIONS = \"You are a helpful AI Agent that can help plan vacations for customers\"\n",
    "agent = ChatCompletionAgent(service_id=\"agent\", kernel=kernel, name=AGENT_NAME)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# User: 'Plan me a sunny vaction'\n",
      "# Agent - TravelAgent: 'Sure! To help you plan a sunny vacation, I need a bit more information. Here are a few questions:\n",
      "\n",
      "1. **Destination Preference:** Do you have a specific region or country in mind (e.g., coastal cities, tropical islands, etc.)?\n",
      "2. **Travel Dates:** When do you plan to travel, and for how long?\n",
      "3. **Budget:** What’s your budget for accommodation, activities, and meals?\n",
      "4. **Activities:** What types of activities are you interested in (beach relaxation, adventure sports, sightseeing, etc.)?\n",
      "5. **Traveling with:** Are you traveling solo, with family, or with friends? Any children or pets?\n",
      "6. **Climate Preferences:** Do you prefer warm, hot, or tropical weather?\n",
      "\n",
      "Once I have this information, I can create a tailored vacation plan for you!'\n"
     ]
    }
   ],
   "source": [
    "async def main():\n",
    "    # Define the chat history\n",
    "    chat_history = ChatHistory()\n",
    "    chat_history.add_system_message(AGENT_INSTRUCTIONS)\n",
    "\n",
    "    user_inputs = [\n",
    "        \"Plan me a sunny vaction\",\n",
    "    ]\n",
    "    for user_input in user_inputs:\n",
    "        # Add the user input to the chat history\n",
    "        chat_history.add_user_message(user_input)\n",
    "        print(f\"# User: '{user_input}'\")\n",
    "        # Invoke the agent to get a response\n",
    "        async for content in agent.invoke(chat_history):\n",
    "            # Add the response to the chat history\n",
    "            chat_history.add_message(content)\n",
    "            print(f\"# Agent - {content.name or '*'}: '{content.content}'\")\n",
    "\n",
    "# For Jupyter notebooks, use this instead of asyncio.run():\n",
    "await main()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
